package br.unicamp.ic.lis.docseaservice.utils;

import org.apache.log4j.Logger;
import org.codehaus.jettison.json.JSONException;
import org.codehaus.jettison.json.JSONObject;

import com.vividsolutions.jts.geom.Geometry;

public class Printer {

	public enum Relationship {
		EQUALS, DISJOINT, INTERSECTS, CROSSES, WITHIN, CONTAINS, OVERLAPS, TOUCHES, COVERS, COVEREDBY
	}

	private static Logger LOG = Logger.getLogger(Printer.class);

	public static void printRelations(Geometry a, Geometry b) {
		JSONObject json = new JSONObject();
		/*
		 * for (Relationship relationship : Relationship.values()) {
		 * 
		 * }
		 */

		try {
			json.put("object1", a.toString());
			json.put("object2", b.toString());
			json.put(Relationship.EQUALS.name().toLowerCase(), a.equals(b));
			json.put(Relationship.DISJOINT.name().toLowerCase(), a.disjoint(b));
			json.put(Relationship.INTERSECTS.name().toLowerCase(),
					a.intersects(b));
			json.put(Relationship.CROSSES.name().toLowerCase(), a.crosses(b));
			json.put(Relationship.WITHIN.name().toLowerCase(), a.within(b));
			json.put(Relationship.CONTAINS.name().toLowerCase(), a.contains(b));
			json.put(Relationship.OVERLAPS.name().toLowerCase(), a.overlaps(b));
			json.put(Relationship.TOUCHES.name().toLowerCase(), a.touches(b));
			json.put(Relationship.COVERS.name().toLowerCase(), a.covers(b));
			json.put(Relationship.COVEREDBY.name().toLowerCase(),
					a.coveredBy(b));

			LOG.info(json);

		} catch (JSONException e) {
			LOG.error(e);
		}
	}

	public static void printDetails(Geometry a) {
		JSONObject json = new JSONObject();

		try {
			json.put("object", a.toString());
			json.put("valid", a.isValid());
			json.put("simple", a.isSimple());
			json.put("empty", a.isEmpty());
			json.put("retangle", a.isRectangle());

			LOG.info(json);

		} catch (JSONException e) {
			LOG.error(e);
		}

	}

	/*
	 * public static void printRelations(Geometry a, Geometry b) { StringBuilder
	 * sb = new StringBuilder(); sb.append(a + " " + b); sb.append("\n");
	 * sb.append("Equal -> " + a.equals(b)); sb.append("\n");
	 * sb.append("Disjoint -> " + a.disjoint(b)); sb.append("\n");
	 * sb.append("Intersects -> " + a.intersects(b)); sb.append("\n");
	 * sb.append("Disjoint -> " + a.disjoint(b)); sb.append("\n");
	 * sb.append("Touches -> " + a.touches(b)); sb.append("\n");
	 * sb.append("Crosses -> " + a.crosses(b)); sb.append("\n");
	 * sb.append("Within -> " + a.within(b)); sb.append("\n");
	 * sb.append("Countains -> " + a.contains(b)); sb.append("\n");
	 * sb.append("Overlaps -> " + a.overlaps(b)); sb.append("\n");
	 * sb.append("Distance -> " + a.distance(b)); LOG.info(sb); }
	 */

}
